package com.wteam.dragon.model.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wteam.dragon.model.pojo.bean.Job;
import com.wteam.dragon.model.pojo.dto.JobDto;
import com.wteam.dragon.model.pojo.vo.JobVo;
import com.wteam.dragon.model.service.JobService;
import com.wteam.dragon.system.aop.log.log.Log;
import com.wteam.dragon.system.basebean.bean.ResultMessage;
import com.wteam.dragon.system.basebean.vo.PageVo;
import com.wteam.dragon.system.util.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 陈晓辉
 * @Date 2020/12/18 10:56
 */
@RestController
@Api(tags = "系统：职业管理")
@RequestMapping("admin/job")
@RequiredArgsConstructor
public class JobController {
    private final JobService jobService;

    @Log("添加岗位")
    @ApiOperation("添加岗位")
    @PostMapping("addJob")
    @PreAuthorize("@el.check('addJob')")
    public ResultMessage addJob(JobVo jobVo){
        Job job = BeanUtil.from(jobVo, Job.class);
        return jobService.addJob(job);
    }

    @Log("删除岗位")
    @ApiOperation("删除岗位")
    @DeleteMapping("delJob")
    @PreAuthorize("@el.check('delJob')")
    public ResultMessage delJob(Long id){
        return jobService.delJob(id);
    }

    @Log("更新岗位")
    @ApiOperation("更新岗位")
    @PutMapping("editJob")
    @PreAuthorize("@el.check('editJob')")
    public ResultMessage editJob(JobVo jobVo){
        Job job = BeanUtil.from(jobVo, Job.class);
        return jobService.editJob(job);
    }

    @GetMapping("pageJob")
    @Log("获得分页职业列表")
    @ApiOperation("获得分页职业列表")
    @PreAuthorize("@el.check('pageJob')")
    public ResultMessage pageJob(PageVo<JobDto> pageVo, Long deptId, String jobName){
        Page<JobDto> page = BeanUtil.fromPage(pageVo);
        return jobService.pageJob(page, deptId, jobName);
    }

    @Log("获得岗位名列表")
    @ApiOperation("获得职业名列表")
    @GetMapping("listJobName")
    @PreAuthorize("@el.check('listJobName')")
    public ResultMessage listJobName(){
        return jobService.listJobName();
    }
}
